package com.tasly.service.impl;

import com.tasly.manager.CarUserManager;
import com.tasly.model.bo.UsersCarsBO;
import com.tasly.model.dto.CarDTO;
import com.tasly.model.dto.UserDTO;
import com.tasly.model.dto.UsersCarsDTO;
import com.tasly.model.entity.CarDO;
import com.tasly.model.entity.UserDO;
import com.tasly.service.UserCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserCarServiceImpl implements UserCarService {
    @Autowired
    private CarUserManager carUserManager;
    @Override
    public UsersCarsDTO getAllUsersCars() {
        UsersCarsBO userCar = carUserManager.getUserCar();
        List<CarDO> cars = userCar.getCars();
        List<CarDTO> carDTOS = new ArrayList<>();
        for(CarDO item : cars){
            CarDTO carDTO = new CarDTO();
            carDTO.setBrand(item.getBrand());
            carDTO.setPower(item.getPower());
            carDTOS.add(carDTO);
        }

        List<UserDO> users = userCar.getUsers();
        ArrayList<UserDTO> userDTOS = new ArrayList<>();
        for(UserDO item : users){
            userDTOS.add(new UserDTO(item.getName()));
        }

        UsersCarsDTO usersCarsDTO = new UsersCarsDTO();
        usersCarsDTO.setCars(carDTOS);
        usersCarsDTO.setUsers(userDTOS);

        return usersCarsDTO;
    }
}
